package com.bjtime.hprinter.Fragments.attrs


import android.graphics.Color
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.LinearLayout
import android.widget.RadioButton
import com.bjtime.designer.view.LineView
import com.bjtime.designer.widget.LineView2
import com.bjtime.hprinter.R
import kotlinx.android.synthetic.main.viewpager_attrs_layout_base.*


class line : Fragment {

    constructor()

    companion object {
        fun newInstance () : line {
            return line ()
        }
    }

    private var mView : View? = null
    private var mLineView : LineView2? = null
    private var FullLineBtn : RadioButton? = null
    private var DottedLineBtn : RadioButton? = null

    fun setView (v : LineView2) {
        mLineView = v
        if (FullLineBtn != null) {
            if (v.getFull ()) {
                FullLineBtn!!.isChecked = true
                DottedLineBtn!!.isChecked = false
            } else {
                FullLineBtn!!.isChecked = false
                DottedLineBtn!!.isChecked = true
            }
        }
    }


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mView = LayoutInflater.from(context).inflate(R.layout.viewpager_attrs_layout_lineview, null)
        mView!!.findViewById<CheckBox>(R.id.attrs_base_expand).setOnCheckedChangeListener({ i, b->
            if (b) {
                mView!!.findViewById<View>(R.id.attrs_base_layout).visibility = View.VISIBLE
                text1.setText(resources.getString(R.string.bastattr_left))
                (text1.parent as LinearLayout).setBackgroundColor(Color.TRANSPARENT)
            } else {
                mView!!.findViewById<View>(R.id.attrs_base_layout).visibility = View.GONE
                text1.setText(resources.getString(R.string.bastattr_expand))
                (text1.parent as LinearLayout).setBackgroundColor(Color.WHITE)
            }
        })

        FullLineBtn = mView!!.findViewById(R.id.attr_line_style_full)
        DottedLineBtn = mView!!.findViewById(R.id.attr_line_style_dotted)
        DottedLineBtn!!.setOnCheckedChangeListener({v,b->
            if (b) {
                if (mLineView != null)
                    mLineView!!.setFull(false)
            }
        })


        FullLineBtn!!.setOnCheckedChangeListener({v,b->
            if (b) {
                if (mLineView != null)
                    mLineView!!.setFull(true)
            }
        })

        return mView
    }
}